title = "分类详情页" 
url = '/:slug|[a-z0-9\-]+-c-\d+.html$' 
title = '分类详情页模板' 
layout = 'default' 
== 
use Jason\Ccshop\Controllers\Filters;
use Jason\Ccshop\Controllers\Categories; 
use Jason\Ccshop\Models\Category; 
use Jason\Ccshop\Models\Product; 
use Jason\Ccshop\Models\Promotion;
use Jason\Ccshop\Components\Catalog;
function onStart(){
	$slugArr = explode('-', str_replace('.html','', $this->param('slug'))); 
	$slug = str_replace(array('price_asc-','price_desc-','popular_desc-', 'newness_desc-'), array(), $this->param('slug')); 
	$id = array_pop($slugArr); 
	array_pop($slugArr); 
	$condition= ['id' => $id];
	$this['paramKey'] = join('-', $slugArr); 
	$categoryModel = Category::where('id', $id)->first(); 
	$this['currentUrl']= str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), substr(request()->getRequestUri(),1));
	$this['sortFlag'] = $slugArr[0]; 
	if(!$categoryModel) { 
		return redirect('/404'); 
	} 
	$this['category'] = $categoryModel; 
	$pids= get('id_sort')?get('id_sort'):null; 
	$pageNumber = get('page')?get('page'):1; 
	if(!empty($pids)){ 
		Cookie::queue('idssort',$pids);
		Cookie::queue('cid',$id); 
		Cookie::queue('pagenumber',$pageNumber); 
	}else{ 
		$pageNumber = Cookie::get('pagenumber'); 
		$cid =Cookie::get('cid'); 
		$currentPage = get('page')?get('page'):1; 
		if($currentPage==$pageNumber && $id==$cid){
		 	$pids = Cookie::get('idssort');
		} 
	} 
	if (!empty($pids)) { 
		$pida = explode(',',$pids); 
		$pd = Product::InStock()->whereIn('id',$pida)->get(); 
		$this['adproducts']= $pd; 
		$this['pida'] = $pida; 
	} 
	if ($this['paramKey'] != $categoryModel['slug']) { 
		$paramKey = explode('-',$this['paramKey']);
		$orderArr = Filters::parseFilterKeyParams($paramKey[0]); 
		if (count($orderArr) == 2) { 
			$order = [$orderArr[0] => $orderArr[1]];
		} 
	} 
	$this['order'] = isset($order) ? $order : ['sort' => 'desc']; 
	$this['products'] = App::make('Jason\Ccshop\Controllers\Products')->getCategoryProducts($categoryModel->id,$this['order']); 
	   //促销产品
    $promotionNow = Promotion::where('name', 'christmas_now')->first();
    $this['collectPromotions'] = [];
    $now = time();
    if(strtotime($promotionNow->from_date) < $now && strtotime($promotionNow->to_date) > $now){
	    $promotions = (new Catalog)->getProductsByPromotionName('christmas_now'); 
	    $collectPromotions = [];
	    foreach($promotions as $promotion){
	       $collectPromotions[$promotion['id']] = true;
	    }
	    $this['collectPromotions'] = $collectPromotions;
    }
} 
== 
{% put page_title %}{{ category.page_title }}{% endput %} 
{% set per = get('per', 20) %} 

{% put pageurl%}
	{{ catalog.canonicalValue(category.url, 'category')|raw }}
{% endput %} 

{% put pageUrl %}
	<link rel="canonical" href="{{ ''|page }}"> 
	{% if products.nextPageUrl %}

	<link rel="next" href="{{ products.nextPageUrl }}"> 
	{% endif %} 
{% endput %} 
{% put meta_keywords %}{{ category.meta_keywords }}{% endput %} 
{% put meta_description %}{{ category.meta_description}}{% endput %} 


{% partial 'catalog/ad-product' adproducts=adproducts pida=pida  pid=products.data[0].id %}
<div class="category_content">
	<!--<div style="overflow: hidden;margin: 5px 0 10px;">-->
	<!--<p class="allItemNum"> 全{{ products.total }} 商品 </p>-->
	<!--{{ products.render|raw }}-->
	<!--</div>-->
	{% partial 'catalog/list-toolbar' products = products.data %}
	<div class="itemList">
		<h2 class="itemList_head" data-category-id="{{ category.id }}">{{ category.name }}</h2>
		<ul class="listUl">
			{% for product in products.data %}
			<li class="product_h">
				<a href="{{ product.url }}">
					<div class="productImg">
						<img src="{{ product.f_thumb }}" data-original="{{ product.f_thumb }}" alt="{{ product.name }}" class="productImgH lazy">
						{% if product.saled > 500 %}
						<span class="hotSale sale_">
							<img src="{{ 'assets/img/hotSale.png'|theme }}" alt="">
						</span>
						{% endif %} {% if product.labels == "newest" %}
						<span class="newSale sale_">
							<img src="{{ 'assets/img/newSale.png'|theme }}" alt="">
						</span>
						{% endif %}
					</div>
					<div class="contBlock">
						<p class="txtGray1 Ellipsis">{{product.name}}</p>
						<p class="txtGray">
						{% if collectPromotions[product.id]%}
							<b>{{ product.id|getDbPrice|formatPrice }} 税込</b>
						{% else %}
							<b>{{ product.price|formatPrice }}</b>税込 &nbsp; 
						{% endif %}
					   {% if product.discount %}
						<span class="proSale">
							<b>{{ product.discount }}</b>OFF</span>
						{% endif %}
						</p>
					</div>
				</a>
			</li>
			{% endfor %}

		</ul>
		<div style="overflow: hidden;margin: 5px 0 10px;">
			<p class="allItemNum"> 全{{ products.total }} 商品 </p>
			{{ products.render|raw }}
		</div>

	</div>
</div>
{% put scripts %}
	<script>
		var dataCategoryId = $(".itemList_head").attr("data-category-id")
		$("#topMenu").find(".mune_").next(".Content").find("ul li").each(function(i,item){
			var id = $(item).attr("data-id");
			if(id == dataCategoryId){
				$(item).parents(".Content").css("display","block").prev().find(".arrow").addClass("bottom");
				return false;
			}
		})
		
	</script>
{% endput %}


{% for key, product in products.data %} 
{% put google_tag_params %} 
var google_tag_params = { ecomm_prodid: "{{product.id}}",
ecomm_pagetype: "category", 
ecomm_totalvalue: {{product.price|ratePrice}} }; 
{% endput %} 
{% endfor %}